<template>
  <div>
    <el-table :data="newList" style="width: 100%">
      <el-table-column prop="number" label="考试编号" width="150">
      </el-table-column>
      <el-table-column prop="subject" label="学科" width="120">
      </el-table-column>
      <el-table-column prop="catalog" label="目录" width="120">
      </el-table-column>
      <el-table-column label="题型" width="120">
        <template slot-scope="{ row }">
          {{ typList[row.questionType] ? typList[row.questionType].label : '' }}
        </template>
      </el-table-column>
      <el-table-column label="题干" width="250">
        <template slot-scope="{ row }">
          <div v-html="row.question"></div>
        </template>
      </el-table-column>
      <el-table-column prop="addDate" label="录入时间" width="120">
      </el-table-column>
      <el-table-column label="难度" width="120">
        <template slot-scope="{ row }">
          {{ difList[row.difficulty] ? difList[row.difficulty].label : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="creator" label="录入人" width="120">
      </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="{ row }">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-view"
            circle
            plain
            @click="btnA(row.id)"
          ></el-button>
          <el-button
            size="mini"
            type="success"
            icon="el-icon-edit"
            circle
            plain
            @click="edit(row)"
          ></el-button>
          <el-button
            size="mini"
            type="danger"
            icon="el-icon-delete"
            circle
            plain
            @click="del(row)"
          ></el-button>
          <el-button
            size="mini"
            type="warning"
            icon="el-icon-check"
            circle
            plain
            @click="add(row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <quseran
      :showDialog.sync="showDialog"
      :questionsData="questionsData"
    ></quseran>
  </div>
</template>

<script>
import { questionType, difficulty } from '@/api/hmmm/constants.js'
import { remove, choiceAdd, detail } from '@/api/hmmm/questions.js'
import quseran from '@/module-hmmm/components/questions-preview.vue'
export default {
  components: {
    quseran
  },
  props: {
    newList: {
      type: Array
    }
  },

  methods: {
    handleClick (row) {
      console.log(row)
    },
    /* 获取试题类型 */
    gettypList () {
      this.typList = questionType
    },
    /* 获取试题难度 */
    getdifList () {
      this.difList = difficulty
    },
    del (row) {
      this.$confirm('你确定删除该题目吗？, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'danger'
      })
        .then(async () => {
          const res = await remove(row)
          console.log(res)
          this.$emit('reList')
        })
        .catch((err) => err)
    },
    add (row) {
      this.addList.id = row.id
      this.$confirm('你确定把改题目加入精品吗？, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          const res = await choiceAdd(this.addList)
          console.log(res)
          this.$emit('reList')
        })
        .catch((err) => err)
    },
    edit (row) {
      this.$router.push({
        path: '/questions/new',
        query: {
          id: row.id
        }
      })
    },
    async btnA (id) {
      const { data } = await detail({ id })
      console.log(data, 123123123)
      this.showDialog = true
      this.questionsData = data
    }
  },
  created () {
    this.getdifList()
    this.gettypList()
  },
  data () {
    return {
      typList: [],
      difList: [],
      dirList: [],
      chkList: [],
      pubList: [],
      dialogVisible: false,
      questionsData: {},
      showDialog: false,
      addList: {
        choiceState: 1,
        id: ''
      },
      rules: {
        chkRemarks: [
          { required: true, message: '请输入审核意见', trigger: 'blur' }
        ]
      }
    }
  }
}
</script>
<style scoped lang="scss"></style>
